from pyurl.url import BaseURL, URL

class Folder(object):
    def __init__(self, path, child=None):
        if isinstance(path, BaseURL):
            self.url = path
        else:
            self.url = URL(path)
            
        if child is not None:
            self.url = URL(self.url, child)
        
    def get_exists(self):
        return self.url.connection.exists(self.url.path)
    
    def __str__(self):
        return str(self.url)
    
    def get_children(self):
        for child in self.url.connection.iter_folder(self.url.path):
            yield URL(self.url, child)
            
    exists = property(get_exists)